TabBar 就是下面紅色框框所圈起來的這個控制項,我們可以點擊上面的圖案進而做到切換頁面的功能!
我們這邊用的是 XIB 的方式來撰寫!
且是用純 Code 生成喔!
super.viewDidLoad()
let globeVC = globeVC()
let clockVC = clockVC()
let stopwatchVC = stopwatchVC()
let timerVC = timerVC()
globeVC.title = "World Clock"
clockVC.title = "Alarm"
stopwatchVC.title = "Stopwatch"
timerVC.title = "Timer"
self.setViewControllers([ globeVC , clockVC , stopwatchVC , timerVC ], animated: false )
guard let items = self.tabBar.items else { return }
let images = [ "globe" , "clock" , "stopwatch" , "timer"]
for x in 0...3 {
items[x].image = UIImage(systemName: images[x])
}
補充:
self.tabBar.backgroundColor = .secondarySystemBackground
(這串程式碼可以改變 TabBar 的背景顏色喔!)
這樣子一個簡單的 TabBar 就完成囉!